﻿using System;
using System.Windows.Forms;
using Autodesk.Revit.Attributes;
using Autodesk.Revit.DB;
using Autodesk.Revit.UI;

namespace YArchitech.HVAC
{
	[Transaction(TransactionMode.Manual)]
	[Regeneration(RegenerationOption.Manual)]
	public class cmdSelManage : IExternalCommand
	{
		public Result Execute(ExternalCommandData revit, ref string message, ElementSet elements)
		{
			Result result;
			try
			{
				if (!WinFormTools.IsAdministrator())
				{
					TaskDialog.Show("盈建科提示", "请以管理员身份运行，否则无法保存数据。");
				}
				RibbonPanel ribbonPanel = null;
				foreach (RibbonPanel ribbonPanel2 in revit.Application.GetRibbonPanels("盈建科工具"))
				{
					if (ribbonPanel2.Name == "选择集")
					{
						ribbonPanel = ribbonPanel2;
						break;
					}
				}
                Autodesk.Revit.UI.ComboBox comboBox = null;
				foreach (RibbonItem ribbonItem in ribbonPanel.GetItems())
				{
					if (ribbonItem.Name == "selList")
					{
                        comboBox = (ribbonItem as Autodesk.Revit.UI.ComboBox);
					}
				}
				if (comboBox != null)
				{
					XmlInfo.currItem = comboBox.Current.ItemText;
				}
				XmlInfo.LoadAttrVal(revit);
				if (WinFormTools.frmSelectSet == null)
				{
					WinFormTools.frmSelectSet = new hyFrmManage(revit);
					WinFormTools.frmSelectSet.Show(WinFormTools.GetRevitForm());
				}
				else
				{
					WinFormTools.frmSelectSet.Activate();
				}
				result = Autodesk.Revit.UI.Result.Succeeded;
			}
			catch
			{
				MessageBox.Show("error");
				result = Autodesk.Revit.UI.Result.Failed;
			}
			return result;
		}
	}
}
